package com.mayi.zds_comment.dao;

import com.mayi.zds_comment.entity.Business;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface BusinessDAO {
    /**
     * 用于添加商户信息的Dao接口方法
     * @param business 接收商户信息的实体类
     */
    @Insert("insert into  zds_business values (#{id},#{name},#{account},#{password}" +
            ",#{licenseImage},#{province},#{city},#{area},#{address},#{isOpen},#{score}" +
            ",#{description},#{categoryId},#{avatar}" +
            ",#{status},#{deliveryArea},#{income})")
    public void add(Business business);

    /**
     * 用于物理删除商户信息的Dao接口方法
     * @param id 商户id
     */
    @Delete("delete from zds_business where id=#{id}")
    public void delete(String id);
    /**
     * 用于修改商户状态
     *
     */
    @Update("update zds_business set id=#{id},name=#{name},account=#{account},password=#{password}" +
            ",license_image=#{licenseImage},province=#{province},city=#{city},area=#{area},address=#{address},is_open=#{isOpen}," +
            "score=#{score},description=#{description},category_id=#{categoryId},avatar=#{avatar}," +
            "status=#{status},delivery_area=#{deliveryArea},income=#{income}")
    public void updateBusiness(Business business);

    /**
     * 用于查询所有的商户
      * @return 返回所有商户列表
     */
    @Select("select * from  zds_business ")
     @Results(id="businessResult",value = {@Result(property = "licenseImage",column = "license_image"),
             @Result(property = "isOpen",column = "is_open"),
             @Result(property = "categoryId",column = "category_id"),
     @Result(property = "deliveryArea",column = "delivery_area")})
    public List<Business> selectAll();

    /**
     * 根据主键查询商户相关信息
     * @param id 主键
     * @return 返回符合要求的商户
     */
    @Select("select *from zds_business where id=#{id}")
    @Results(id="businessResults",value = {@Result(property = "licenseImage",column = "license_image"),
            @Result(property = "isOpen",column = "is_open"),
            @Result(property = "categoryId",column = "category_id"),
            @Result(property = "deliveryArea",column = "delivery_area")})
    public Business getByid(String id);
}
